# Need to install Google Data API for Python

import gdata.spreadsheet.service
from getpass import getpass
import sys

username = sys.argv[1]
password = getpass("Password: ")

client = gdata.spreadsheet.service.SpreadsheetsService()
if username.endswith("@gmail.com"):
  client.email = username
else:
  client.email = username + "@gmail.com"

client.password = password
client.ProgrammaticLogin()

s_key = "0ApCQmuJA1Dw8dHpsY0RGTEpLMkI4VENXa2g5X2VVMGc"

worksheets = client.GetWorksheetsFeed(s_key)

w_key = worksheets.entry[0].id.text.split("/")[-1]

datafeed = client.GetListFeed(s_key, w_key)

for (i, row) in enumerate(datafeed.entry):
  attrs = row.custom.keys()
  data = dict((x, row.custom[x].text) for x in attrs)
  print i, "%s (%s)" % (data['sectiontitle'], data['sec'])
